package com.ftg.learn.sys.user.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ftg.learn.comm.entity.sys.Resources;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 资源管理
 * @author kangjx
 * @date 2022-10-23
 */
@Mapper
public interface ResourcesMapper extends BaseMapper<Resources> {


    /**
     * 查询 当前用户 uid的全部权限
     * @param uid 用户 编号
     * @return List<Resources>
     */
    @Select("select * from sys_resources where id in (" +
            "    select res_id from sys_role_resources where r_id in (" +
            "        select sys_user_role.r_id from sys_user_role where u_id = #{uid} and is_deleted =0" +
            "    ) and is_deleted =0" +
            ") and is_deleted =0;")
    List<Resources> showResourceByUid(@Param("uid") Integer uid);

    @Update("update sys_resources set res_title = #{resName} where id =#{resid}")
    int udpateResName(@Param("resid") Integer resid, @Param("resName") String resName);
}
